﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SQLite;

namespace Sunboxsoft.ASMS.Client.Domain.LocalService
{
    public class DeleteService
    {
        public void DeleteMasterDataAndItems(string code)
        {
            using (SQLiteConnection connection = new SQLiteConnection(SQLiteDatabase.ConnectionString))
            {
                connection.Open();
                DeleteMasterDataAndItems(connection, code);
            }
        }
        
        public void DeleteMasterDataAndItems(SQLiteConnection connection, string code)
        {
            SQLiteCommand command = new SQLiteCommand(connection);
            command.CommandText = "delete from ASMS_MasterData where [Code]=@Code";
            SQLiteParameter pCode = command.CreateParameter();
            pCode.ParameterName = "@Code";
            pCode.Value = code;
            command.Parameters.Add(pCode);

            command.ExecuteNonQuery();


            SQLiteCommand commandItems = new SQLiteCommand(connection);
            commandItems.CommandText = "delete from ASMS_MasterDataItem where [MasterDataCode]=@MasterDataCode";
            SQLiteParameter pMDCode = commandItems.CreateParameter();
            pMDCode.ParameterName = "@MasterDataCode";
            pMDCode.Value = code;
            commandItems.Parameters.Add(pMDCode);

            commandItems.ExecuteNonQuery();
        }
    }
}
